<?php
class Contus_Emailnewsletter_Block_Emailnewsletter extends Mage_Core_Block_Template {
    public function _prepareLayout() {
        return parent::_prepareLayout();
    }

    public function getEmailnewsletter() {
        $model = Mage::getModel('catalog/product'); //getting product model
        $productdetail = $model->load($productId);//print_r($productdetail);
        $current_product =  $productdetail->getId();
        $currentproductname = $productdetail->getName();
        $currentproductimage = Mage::helper('catalog/image')->init($productdetail, 'image')->resize(386,338);
        $discount_price =  $productdetail->getPrice()-$productdetail->getSpecialPrice();
        $product_saveprice = $discount_price ;
        $discount = ($discount_price*100)/ $productdetail->getPrice();
        $discount = round($discount);
        $currentdiscount = $discount;
        $Companywebsite =  $productdetail->getCustomer_website();
        $Companyname=$productdetail->getCustomersite();
        $product_worth = $productdetail->getPrice();
        $product_price = $productdetail->getSpecialPrice();
        $product_description = $productdetail->getDescription();
        $deal_date= date('M d Y',strtotime(now()));
        $resource = Mage::getSingleton('core/resource');
        $newsletterEmail = $resource->getConnection('core_write');
        $tprefix = (string)Mage::getConfig()->getTablePrefix();
        $newsletterTable = $resource->getTableName('newsletter/subscriber');
        $email_list = $newsletterEmail->fetchAll("Select subscriber_email from ".$tprefix."newsletter_subscriber
                                                  where subscriber_city = '".$city."' AND subscriber_status =1");
        $i = 0;
        $tocustomer = array();
        if( count($email_list)>0 ) {
            foreach($email_list as $rows) {
                $tocustomer[$i] = $rows['subscriber_email'];
                $i++;
            }
        }
        $i = 0;
        $tocustomer = array();
        if( count($email_list)>0 ) {
            foreach($email_list as $rows) {
                $tocustomer[$i] = $rows['subscriber_email'];
                $i++;
            }
        }
        $postObject = new Varien_Object();
        $postObject->setData(array('deal_date' => $deal_date,'product_description' => $product_description,'product_saveprice' => $product_saveprice,'productname' =>  $currentproductname,'product_price' => floor($product_price),'productimage' => $currentproductimage,'discount' =>  $discount,'companywebsite' =>  $Companywebsite,'product_worth' => floor($product_worth),'product_city' => $city,'company_address' => $Companyname));
        $mailTemplate = Mage::getModel('core/email_template');
        $mailTemplate->setSenderName(Mage::getStoreConfig('design/head/default_title'));
        $mailTemplate->setSenderEmail(Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT));
        $mailTemplate->setTemplateSubject('Newsletter Subscription From '.Mage::getStoreConfig('design/head/default_title'));

        /* @var $mailTemplate Mage_Core_Model_Email_Template */
        $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                ->sendTransactional(
                '3',
                Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                $tocustomer,
                Mage::getStoreConfig('design/head/default_title'),
                array('deallist' => $postObject)
        );

        if (!$mailTemplate->getSentSuccess()) {
            return "nirmal";
        }
       // return $this->getData('emailnewsletter');
        return "testing";
    }

    public function getname123()
    {
     return "testing";
    }
}